import type {ConfigEnv} from 'vite'
import {loadEnv} from 'vite'

import vue from '@vitejs/plugin-vue'
import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
import ViteFonts from 'unplugin-fonts/vite'
import WindiCSS from 'vite-plugin-windicss'

// Utilities
import { fileURLToPath, URL } from 'node:url'
export default (config: ConfigEnv) => {
  return {
    // base: '/public/home_new',
    base: './',
    plugins: [
      vue({
        template: { transformAssetUrls }
      }),
      vuetify({
        autoImport: true,
      }),
      ViteFonts({
        google: {
          families: [{
            name: 'Roboto',
            styles: 'wght@100;300;400;500;700;900',
          }],
        },
      }),
      WindiCSS(),
    ],
    define: { 'process.env': {} },
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      },
      extensions: ['.js', '.json', '.jsx', '.mjs', '.ts', '.tsx', '.vue',],
    },
    server: {
      port: 3000,
      proxy: {
        '/api': {
          target: loadEnv(config.mode, process.cwd()).VITE_PROXY_API,
          changeOrigin: true,
          rewrite: (path: string) => path.replace(/^\/api/, '')
        }
      }
    },
  }
}
